﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace br.com.portocs.unidaacademico.framework
{
    public static class StringExtensions
    {
        public static string PluralizePortugueseBrazilian(this string word)
        {
            if (word.Length > 2)
            {
                var termination = word.Substring(word.Length - 2);
                word = word.Substring(0, word.Length - 2);

                //  Regras
                //  se terminacao[1] = "r" ou "z" => terminacao + "es"
                if (termination[1].Equals("r") || termination[1].Equals("z"))
                    termination = string.Format("{0}es", termination);

                //  se terminacao[1] = "m" => terminacao.Replace("m", "ns")
                else if (termination[1].Equals("m"))
                    termination = termination.Replace("m", "ns");

                //  se terminacao = "al" ou "el" ou "ol" ou "ul" => terminacao.Replace("l", "is")
                else if (termination.Equals("al") ||
                    termination.Equals("el") ||
                    termination.Equals("ol") ||
                    termination.Equals("ul"))
                {
                    termination = termination.Replace("l", "is");
                }

                //  se terminacao = "il" => terminacao.Replace("l", "s")
                else if (termination.Equals("il"))
                    termination = termination.Replace("l", "s");

                //  se terminacao = "ao" => terminacao.Replace("ao", "oes")
                else if (termination.Equals("ao"))
                    termination = termination.Replace("ao", "oes");

                else
                    termination += "s";

                word += termination;
            }

            return word;
        }
    }
}
